<?php
namespace app\common\behavior;
use think\Exception;
use think\Lang;
use think\Loader;

class Order 
{
	/**
	 * 创建订单后置操作
	 * @param  [type] &$data [description]
	 * @return [type]        [description]
	 */
    public function afterCreateOrder(&$order_info)
    {
    	try {
            // Loader::model('Notices')->sendNotice(0, Lang::get('Your order has been generated'), Lang::get('Your order has been generated, please pay as soon as possible!'), Loader::model('Users')->getLoginUserInfo('sign'));
    	} catch (\Exception $e) {
    		
    	}
        
    }

    public function afterLockOrder(&$order_info)
    {
        try {
            \think\Queue::later(1800, 'common/Order@unLock', $order_info->number);
        } catch (\Exception $e) {
            
        }
    }

    public function beforeCanceOrder(&$order_info)
    {
        try {
            
        } catch (\Exception $e) {
            
        }
    }

    /**
     * 取消订单后置操作
     * @param  [type] &$data [description]
     * @return [type]        [description]
     */
    public function afterCanceOrder(&$order_info)
    {
    	try {
    		
    	} catch (\Exception $e) {
    		
    	}
    }

    public function afterCompleteOrderPay(&$order_info)
    {
    	try {
            $notice_instance = \services\notices\Notice::instance();
            $user_info       = $this->getUserInfo($order_info->order_user_id);
            if ($user_info->email) {
                $recipients['mail'] = $user_info->email;
            }

            $recipients['sign'] = $user_info->sign;

            $notice_instance->send($recipients, Lang::get('Order has been paid successfully'), Lang::get('Order has been paid successfully'));

    	} catch (\Exception $e) {
    		
    	}
    }

    public function afterCompleteOrder(&$order_info)
    {
        try {
            
        } catch (\Exception $e) {
            
        }
    }

    public function afterCancelPayOrder(&$order_info)
    {
    	try {
            
        } catch (\Exception $e) {
            
        }
    }

    protected function getUserInfo($user_id)
    {
        return Loader::model('common/Users')->getUserInfo($user_id);
    }
}